package cn.iocoder.yudao.adminserver.modules.system.convert.notice;

import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.adminserver.modules.system.controller.notice.vo.SysNoticeCreateReqVO;
import cn.iocoder.yudao.adminserver.modules.system.controller.notice.vo.SysNoticeRespVO;
import cn.iocoder.yudao.adminserver.modules.system.controller.notice.vo.SysNoticeUpdateReqVO;
import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.notice.SysNoticeDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.Map;

@Mapper
public interface SysNoticeConvert {

    SysNoticeConvert INSTANCE = Mappers.getMapper(SysNoticeConvert.class);

    PageResult<SysNoticeRespVO> convertPage(PageResult<SysNoticeDO> page);

    default SysNoticeRespVO convert(SysNoticeDO bean, Map<Long, SysUserDO> userMap){
        if ( bean == null ) {
            return null;
        }
        SysNoticeRespVO respVO = new SysNoticeRespVO();
        respVO.setTitle( bean.getTitle() );
        respVO.setType( bean.getType() );
        respVO.setContent( bean.getContent() );
        respVO.setStatus( bean.getStatus() );
        respVO.setPublisher(bean.getPublisher());
        respVO.setCreateTime(bean.getCreateTime());
        respVO.setId(bean.getId());
        if(userMap != null && !userMap.isEmpty()){
            SysUserDO user = userMap.get(bean.getPublisher());
            respVO.setPublisherName(user == null ? "" : user.getNickname());
        }
        return respVO;
    }

    SysNoticeDO convert(SysNoticeUpdateReqVO bean);

    default SysNoticeDO convert(SysNoticeCreateReqVO bean){
        if ( bean == null ) {
            return null;
        }
        SysNoticeDO sysNoticeDO = new SysNoticeDO();
        sysNoticeDO.setTitle( bean.getTitle() );
        sysNoticeDO.setType( bean.getType() );
        sysNoticeDO.setContent( bean.getContent() );
        sysNoticeDO.setStatus( bean.getStatus() );
        sysNoticeDO.setPublisher(bean.getPublisher());
        return sysNoticeDO;
    }

}
